/*

Power digit sum
Problem 16
215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 2^1000?
*/

var Enumerable = require('linq');
var start = new Date().getTime();
var BigNumber = require('./BigNumber'); // Example for including files
var Big = require('big.js');

var solveTask = function (number, power) {
    var x = new Big(number).pow(power);
    var a =  Enumerable.from(x.toFixed()).aggregate(0, function(a, b) {
        if(b != '0') {
            return a + parseInt(b);   
        } else {
            return a;    
        }
    });

    return a;
};

var result = solveTask(2,1000);
console.log("Result: ", result);

var end = new Date().getTime();
var time = end - start;

console.log("Time: ", time);

require('readline')
    .createInterface(process.stdin, process.stdout)
    .question("Press [Enter] to exit...", function(){
        process.exit();
});